package com.baomidou.springwind.controller.city;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.kisso.annotation.Permission;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springwind.controller.BaseController;
import com.baomidou.springwind.entity.*;
import com.baomidou.springwind.enums.NodeTypeEnum;
import com.baomidou.springwind.pojo.*;
import com.baomidou.springwind.service.MessageService;
import com.baomidou.springwind.mapper.MessageDao;
import com.baomidou.springwind.service.ProjectService;
import com.baomidou.springwind.service.WeekOrderService;
import com.baomidou.springwind.service.WorkTimeService;
import com.baomidou.springwind.service.DepartmentsHangerService;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 用户留言
 * </p>
 *
 * @Author huangtao
 * @Date 2017-8-21
 */
@Controller
@RequestMapping("/other/questionMessage")
public class MessageController extends BaseController {

    @Autowired
    private MessageService messageService;
    @Autowired
    private MessageDao messageDao;

    /**
     *
     */
    @RequestMapping("/list")
    @Permission("1001")
    public String messageList(Model model) {
        return pjaxPath("/user/questionMessage", model);
    }
    @RequestMapping("/listAll")
    @Permission("1001")
    public String messageListAll(Model model) {
        return pjaxPath("/user/questionMessageAll", model);
    }

    /**
     *
     */
    @ResponseBody
    @RequestMapping("/getData")
    @Permission("1001")
    public String getData(Page<Message> page,String batchId) {
        page = new Page<Message>(page.getCurrent(), page.getSize());
        EntityWrapper<Message> wrapper = new EntityWrapper<Message>();
        wrapper.eq("operator_id", getCurrentUserId());
        page = messageService.selectPage(page, wrapper);
        return jsonPage(page);
    }
    /**
     *
     */
    @ResponseBody
    @RequestMapping("/getDataAll")
    @Permission("1001")
    public String getDataAll(Page<Message> page,String batchId) {
        page = new Page<Message>(page.getCurrent(), page.getSize());
        EntityWrapper<Message> wrapper = new EntityWrapper<Message>();
        wrapper.orderBy("create_time");
        page = messageService.selectPage(page, wrapper);
        return jsonPage(page);
    }
    @ResponseBody
    @RequestMapping("/save1")
    @Permission("1001")
    public String save1(Page<Message> page,String batchId) {
        Message message=new Message();
        message.setTitle(request.getParameter("title"));
        message.setContent(request.getParameter("content"));
        message.setCreateTime(new Date());
        message.setOperatorId(getCurrentUserId());
        User user=userService.selectById(getCurrentUserId());
        message.setName(user.getLoginName());
        messageService.insert(message);
        return callbackSuccess("成功");
    }


}
